package com.jwdf.uda.http.action;

import android.content.Context;
import android.text.TextUtils;

import com.jwdf.uda.bean.PbBean;
import com.jwdf.uda.http.AHttpService;
import com.jwdf.uda.http.ApiService;
import com.jwdf.uda.utils.StringUtils;
import com.jwdf.uda.utils.TextUtil;

import retrofit2.Call;

/**
 * 类说明：
 * 作者：huangqiuxin on 2016/5/13 17:05
 * 邮箱：648859026@qq.com
 */
public class UserUpdateInfoAction extends AHttpService<PbBean.PbResUserUpdateInfo> {
    /**
     * 更新用户信息接口
     *
     * @param context
     * @param username
     * @param nickname
     * @param avatarImageToken
     * @param sex
     * @return
     */
    public static UserUpdateInfoAction newInstance(Context context, String username, String nickname, String avatarImageToken, PbBean.PbSignUserSex sex) {
        return new UserUpdateInfoAction(context, username, nickname, avatarImageToken, sex);
    }

    public static UserUpdateInfoAction newInstance(Context context, String username, String nickname, String avatarImageToken) {
        return new UserUpdateInfoAction(context, username, nickname, avatarImageToken);
    }

    public static UserUpdateInfoAction newInstance(Context context, String nickname, String imageToken, PbBean.PbSignUserSex sex) {
        return new UserUpdateInfoAction(context, nickname, imageToken, sex);
    }

    public static UserUpdateInfoAction newInstance(Context context, String nickname, PbBean.PbSignUserSex sex) {
        return new UserUpdateInfoAction(context, nickname, sex);
    }

    public static UserUpdateInfoAction newInstance(Context context, PbBean.PbSignUserSex sex) {
        return new UserUpdateInfoAction(context, sex);
    }

    public static UserUpdateInfoAction newInstance(Context context, String introduction) {
        return new UserUpdateInfoAction(context, introduction);
    }

    public static UserUpdateInfoAction newInstance(String coverImageToken, Context context) {
        return new UserUpdateInfoAction(coverImageToken, context);
    }

    public static UserUpdateInfoAction newInstance(Context context, String birthday, PbBean.PbSignUserConstellation userConstellation) {
        return new UserUpdateInfoAction(context, birthday, userConstellation);
    }

    private String username;
    private String nickname;
    private String avatarImageToken;
    private String coverImageToken;
    private PbBean.PbSignUserSex sex;
    private String introduction;
    private String birthday;
    private PbBean.PbSignUserConstellation userConstellation;

    private UserUpdateInfoAction(Context context, String username, String nickname, String avatarImageToken, PbBean.PbSignUserSex sex) {
        super(context);
        this.username = username;
        this.nickname = nickname;
        this.avatarImageToken = avatarImageToken;
        this.sex = sex;
    }

    private UserUpdateInfoAction(Context context, String nickname, String imageToken, PbBean.PbSignUserSex sex) {
        super(context);
        this.nickname = nickname;
        this.avatarImageToken = imageToken;
        this.sex = sex;
    }

    private UserUpdateInfoAction(Context context, String nickname, PbBean.PbSignUserSex sex) {
        super(context);
        this.nickname = nickname;
        this.sex = sex;
    }


    private UserUpdateInfoAction(Context context, String nickname, String username, String avatarImageToken) {
        super(context);
        this.nickname = nickname;
        this.username = username;
        this.avatarImageToken = avatarImageToken;
    }

    private UserUpdateInfoAction(Context context, PbBean.PbSignUserSex sex) {
        super(context);
        this.sex = sex;
    }

    private UserUpdateInfoAction(Context context, String introduction) {
        super(context);
        this.introduction = introduction;
    }

    private UserUpdateInfoAction(String coverImageToken, Context context) {
        super(context);
        this.coverImageToken = coverImageToken;
    }

    private UserUpdateInfoAction(Context context, String birthday, PbBean.PbSignUserConstellation userConstellation) {
        super(context);
        this.birthday = birthday;
        this.userConstellation = userConstellation;
    }

    @Override
    protected Call newRetrofitCall(ApiService apiService, PbBean.PbBaseClientInfo.Builder baseBuilder) {
        PbBean.PbReqUserUpdateInfo.Builder builder = PbBean.PbReqUserUpdateInfo.newBuilder();
        builder.setBaseClientInfo(baseBuilder);
        if (!TextUtils.isEmpty(username)) {
            builder.setUsername(StringUtils.filterNullAndTrim(username));
        }
        if (!TextUtils.isEmpty(nickname)) {
            builder.setNickname(StringUtils.filterNullAndTrim(nickname));
        }
        if (!TextUtils.isEmpty(avatarImageToken)) {
            builder.setAvatarImageToken(StringUtils.filterNullAndTrim(avatarImageToken));
        }
        if (!TextUtils.isEmpty(coverImageToken)) {
            builder.setCoverImageToken(coverImageToken);
        }
        if (sex != null) {
            builder.setSex(sex);
        }
        if (!TextUtils.isEmpty(introduction)) {
            if (introduction.equals("空")) {
                builder.setIntroduction("");
            } else {
                builder.setIntroduction(introduction);
            }
        }
        if (!TextUtil.isEmpty(birthday)) {
            builder.setBirthday(birthday);
        }
        if(userConstellation != null ) {
            builder.setConstellation(userConstellation);
        }

        return apiService.updateUserInfo(builder.build());
    }
}
